import {
    _decorator,
    Color,
    color,
    Component,
    instantiate,
    Label,
    Node,
    Prefab,
    Sprite,
    SpriteFrame,
    tween,
    Tween,
    UITransform,
    v3,
    Vec3
} from 'cc';
import {GameMain} from "./GameMain";
import LevelCfgItem from "./LevelCfgItem";
import {LevelConditionBall} from "./LevelConditionBall";
import {BallColorIdx, GameMode, ItemPrice, Items, NativeEvt} from "./GameConfig";
import {AudioClipID, AudioManager} from "./AudioManager";
import Platform, {PlatformType} from "./Platform";

const { ccclass, property } = _decorator;

@ccclass('MainUI')
export class MainUI extends Component {

    @property({type:Prefab})
    ballPrefab:Prefab=null;

    @property({type:Prefab})
    starPrefab:Prefab=null;

    @property({type:[SpriteFrame]})
    diffSpriteFrames:Array<SpriteFrame>=[];

    @property({type:[SpriteFrame]})
    diffTitleSpriteFrames:Array<SpriteFrame>=[];

    public topNode:Node=null;
    public topBarNode:Node=null;
    public topBarBgSprite:Sprite=null;
    public topBarTitleSprite:Sprite=null;
    public topBarTitleLabel:Label=null;
    public ballAttach:Node=null;
    public stepNumLabel:Label=null;
    public starAttachNode:Node=null;

    public remainSteps:number=0;

    public bottomNode:Node=null;
    public stripSprite:Sprite=null;
    public stripSpriteUITrans:UITransform=null;

    public stripLSprite:Sprite=null;
    public stripLSpriteUITrans:UITransform=null;
    public stripRSprite:Sprite=null;
    public stripRSpriteUITrans:UITransform=null;

    public conditionBalls:Array<LevelConditionBall>=[];

    public topLayerAttachNode:Node=null;

    //左右star 和 金币 bar
    public leftStarBarNode:Node=null;
    public rightMoneyBarNode:Node=null;
    public starNode:Node=null;
    public starNumLabel:Label=null;

    public moneyNode:Node=null;
    public moneyNumLabel:Label=null;

    public ballsMaskSprite:Sprite=null;

    public itemBarNode:Node=null;
    public itemsNode:Node=null;
    public bombTipNode:Node=null;
    public rocketTipNode:Node=null;
    public bombItemSprite:Sprite=null;

    private inited:boolean=false;

    public static readonly leftBarStartPos:Vec3=v3(-710, -315, 0);
    public static readonly leftBarDstPos:Vec3=v3(-400, -315, 0);
    public static readonly rightBarStartPos:Vec3=v3(710, -315, 0);
    public static readonly rightBarDstPos:Vec3=v3(400, -315, 0);
    public static readonly topBarStartPos:Vec3=v3(0, -600, 0);

    public static readonly conditionBallInterval:Array<number>=[0, 110, 90, 80, 70, 66];

    onLoad()
    {
        this.init();
    }

    public init()
    {
        if(this.inited)
            return;

        this.topNode=this.node.getChildByName("top");
        this.topBarNode=this.topNode.getChildByName("topBar");
        this.topBarBgSprite=this.topBarNode.getChildByName("bgSprite").getComponent(Sprite);
        this.topLayerAttachNode=this.node.parent.getChildByName("topAttach").getChildByName("top");

        let titleNode:Node=this.topBarNode.getChildByName("title");
        this.topBarTitleSprite=titleNode.getComponent(Sprite);
        this.topBarTitleLabel=titleNode.getChildByName("Label").getComponent(Label);

        let conditionBgNode:Node=this.topBarNode.getChildByName("levelConditionBg");
        this.ballAttach=conditionBgNode.getChildByName("ballAttach");
        this.stepNumLabel=this.topBarNode.getChildByName("step").getChildByName("bg").getChildByName("stepNum").getComponent(Label);
        this.starAttachNode=this.topBarNode.getChildByName("step").getChildByName("starsAttach");

        this.bottomNode=this.node.getChildByName("bottom");
        let stripParent:Node=this.bottomNode.getChildByName("progressStrip");
        let stripSpriteNode:Node=stripParent.getChildByName("sprite");
        this.stripSprite=stripSpriteNode.getComponent(Sprite);
        this.stripSpriteUITrans=stripSpriteNode.getComponent(UITransform);

        stripSpriteNode=stripParent.getChildByName("spriteL");
        this.stripLSprite=stripSpriteNode.getComponent(Sprite);
        this.stripLSpriteUITrans=stripSpriteNode.getComponent(UITransform);

        stripSpriteNode=stripParent.getChildByName("spriteR");
        this.stripRSprite=stripSpriteNode.getComponent(Sprite);
        this.stripRSpriteUITrans=stripSpriteNode.getComponent(UITransform);

        this.leftStarBarNode=this.topNode.getChildByName("topLeftBar");
        this.rightMoneyBarNode=this.topNode.getChildByName("topRightBar");
        this.ballsMaskSprite=this.node.parent.getChildByName("ballMask").getComponent(Sprite);
        this.starNode=this.leftStarBarNode.getChildByName("scale").getChildByName("star");
        this.starNumLabel=this.leftStarBarNode.getChildByName("num").getComponent(Label);

        this.moneyNode=this.rightMoneyBarNode.getChildByName("scale").getChildByName("money");
        this.moneyNumLabel=this.rightMoneyBarNode.getChildByName("num").getComponent(Label);

        this.itemBarNode=this.topNode.getChildByName("itemBar");
        this.itemsNode=this.itemBarNode.getChildByName("items");

        let topNode:Node=GameMain.instance.ballParent.parent;
        this.bombTipNode=topNode.getChildByName("itemBar").getChildByName("bombSelected");
        this.rocketTipNode=topNode.getChildByName("itemBar").getChildByName("rocketSelected");
        this.bombItemSprite=this.bombTipNode.getChildByName("bomb").getComponent(Sprite);

        this.inited=true;
    }

    public updateUI()
    {

    }

    public updateStarLabel()
    {
        this.starNumLabel.string="" + GameMain.instance.gameData.star;
    }

    public updateMoneyLabel()
    {
        this.moneyNumLabel.string="" + GameMain.instance.gameData.money;
    }

    public showGameUI()
    {
        this.init();
        this.updateConditionUI();

        this.startUIFadeIn();
    }

    public close()
    {
        this.topBarNode.active=false;
        this.leftStarBarNode.setPosition(MainUI.leftBarStartPos);
        this.rightMoneyBarNode.setPosition(MainUI.rightBarStartPos);
    }

    public startUIFadeIn()
    {
        this.updateStarLabel();
        this.updateMoneyLabel();

        this.topBarNode.active=true;
        this.topBarNode.setParent(this.topLayerAttachNode);
        this.leftStarBarNode.setPosition(MainUI.leftBarStartPos);
        this.rightMoneyBarNode.setPosition(MainUI.rightBarStartPos);
        this.topBarNode.setPosition(MainUI.topBarStartPos);

        this.ballsMaskSprite.node.active=true;

        this.scheduleOnce(()=>{

            tween(this.topBarNode).to(0.55, { position: Vec3.ZERO}, {easing:"backIn"}).call(()=>{
                this.ballsMaskSprite.node.active=false;
                this.topBarTitleSprite.node.active=false;
            }).start();
        }, 2);

        this.scheduleOnce(()=>{
            tween(this.leftStarBarNode).to(0.45, { position: MainUI.leftBarDstPos}).start();
            tween(this.rightMoneyBarNode).to(0.45, { position: MainUI.rightBarDstPos}).start();
        }, 2.5);

        this.showItemBar();
    }

    //更新道具ui
    public updateItemBar()
    {
        let item1LockNode:Node=this.itemsNode.children[1].getChildByName("lock");
        let item1UnlockNode:Node=this.itemsNode.children[1].getChildByName("unlock");
        let item2LockNode:Node=this.itemsNode.children[2].getChildByName("lock");
        let item2UnlockNode:Node=this.itemsNode.children[2].getChildByName("unlock");
        if(GameMain.instance.gameData.curLevelId>=4)
        {
            item1LockNode.active = false;
            item1UnlockNode.active=true;
        }
        else
        {
            item1LockNode.active = true;
            item1UnlockNode.active=false;
        }

        if(GameMain.instance.gameData.curLevelId>=9)
        {
            item2LockNode.active=false;
            item2UnlockNode.active=true;
        }
        else
        {
            item2LockNode.active=true;
            item2UnlockNode.active=false;
        }
    }

    public hideBombTip()
    {
        GameMain.instance.resetCurSelItem();
        this.bombTipNode.active=false;
        this.bombItemSprite.node.setPosition(-280, 0, 0);
        this.bombItemSprite.color=color(255, 255, 255, 255);

        this.showItemBar(0.5);
    }

    public hideRocketTip()
    {
        GameMain.instance.resetCurSelItem();
        this.rocketTipNode.active=false;
        this.showItemBar(0);
    }

    public showItemBar(delay:number=2.75)
    {
        let levelCfg:LevelCfgItem=GameMain.getCurLevelCfg();
        if(levelCfg.levelType===GameMode.LineGame)
        {
            for(let i=0;i<this.itemsNode.children.length;i++)
            {
                this.itemsNode.children[i].active=false;
            }
            return;
        }

        this.bombTipNode.active=false;
        this.rocketTipNode.active=false;
        this.updateItemBar();

        for(let i=0;i<this.itemsNode.children.length;i++)
        {
            this.itemsNode.children[i].active=false;
            this.itemsNode.children[i].setScale(0.3, 0.3, 1);
        }

        this.itemsNode.active=true;

        this.scheduleOnce(()=>{
            for(let i=0;i<this.itemsNode.children.length;i++)
            {
                this.itemsNode.children[i].active=true;
                tween(this.itemsNode.children[i]).to(0.5, {scale:Vec3.ONE },{easing:"backOut"}).start();
            }
        }, delay);
    }

    public item0Clicked()
    {
        console.log('item0Clicked')
        if(GameMain.instance.gameData.money < ItemPrice.Bomb)
        {
            GameMain.instance.getMoneyUI.show();
            return;
        }

        //不能有连接球的操作
        if(GameMain.instance.gameOper.getConnectedGridsCount()>0)
            return;

        this.itemsNode.active=false;
        this.bombTipNode.active=true;
        GameMain.instance.setCurSelItem(Items.Bomb);
    }

    public item1Clicked()
    {
        console.log('item0Clicked1')
        if(GameMain.instance.gameData.curLevelId<4)
            return;

        if(GameMain.instance.gameData.money < ItemPrice.Rocket)
        {
            GameMain.instance.getMoneyUI.show();
            return;
        }

        //不能有连接球的操作
        if(GameMain.instance.gameOper.getConnectedGridsCount()>0)
            return;

        this.itemsNode.active=false;
        this.rocketTipNode.active=true;
        GameMain.instance.setCurSelItem(Items.Rocket);
    }

    public item2Clicked()
    {
        console.log('item0Clicked2')
        if(GameMain.instance.gameData.curLevelId<9)
            return;
        if(GameMain.instance.gameData.money < ItemPrice.Refresh)
        {
            GameMain.instance.getMoneyUI.show();
            return;
        }

        //不能有连接球的操作
        if(GameMain.instance.gameOper.getConnectedGridsCount()>0)
            return;

        if(GameMain.instance.getCurSelItem()===Items.Using)
            return;

        GameMain.instance.gameData.addMoney(-ItemPrice.Refresh);
        this.updateMoneyLabel();
        GameMain.instance.refreshClear();
        GameMain.instance.setCurSelItem(Items.Using);
        this.scheduleOnce(()=>{
            GameMain.instance.resetCurSelItem();
        }, 1);
    }

    public bombMoveTo(gridIdx:number, cb:Function)
    {
        console.log('点击球球')
        let targetWorldPos:Vec3=GameMain.instance.grids[gridIdx].node.getWorldPosition();
        let targetPos:Vec3=this.bombItemSprite.node.parent.getComponent(UITransform).convertToNodeSpaceAR(targetWorldPos);
        tween(this.bombItemSprite.node)
            .to(0.5, {position: v3(targetPos.x, targetPos.y, targetPos.z)})
            .call(() =>
            {
                AudioManager.playClip(AudioClipID.Bomb);
                tween(this.bombItemSprite.node)
                    .to(0.7, {}, {
                        onUpdate: (target, ratio: number) => {
                            this.bombItemSprite.color = color(255, 255, 255, 255 * (1-ratio));
                        }
                    })
                    .call(() => {
                        this.hideBombTip();
                    })
                    .start();

                if(cb)
                    cb();
            })
            .start();
    }

    public clearConditionBalls()
    {
        this.conditionBalls.splice(0, this.conditionBalls.length);
    }

    public resetConditionUI()
    {
        for(let i=0;i<this.conditionBalls.length;i++)
        {
            this.conditionBalls[i].reset();
        }

        let levelCfg:LevelCfgItem=GameMain.getCurLevelCfg();
        this.remainSteps=levelCfg.stepLimit;
        this.stepNumLabel.string=""+levelCfg.stepLimit;
    }

    //更新关卡条件显示
    public updateConditionUI()
    {
        //清除ballAttach
        this.ballAttach.destroyAllChildren();
        this.ballAttach.removeAllChildren(true);

        this.clearConditionBalls();
        //分析level cfg
        let levelCfg:LevelCfgItem=GameMain.getCurLevelCfg();
        this.remainSteps=levelCfg.stepLimit;
        this.stepNumLabel.string=""+levelCfg.stepLimit;

        if(levelCfg.levelType===0)
        {
            let conditionCnt:number=levelCfg.conditions.length;
            for (let i = 0; i < conditionCnt; i++)
            {
                let ballObj = instantiate(this.ballPrefab);
                this.ballAttach.addChild(ballObj);
                ballObj.name = levelCfg.conditions[i].c;
                ballObj.setPosition((i - (conditionCnt-1)*0.5) * MainUI.conditionBallInterval[conditionCnt-1], 0, 0);

                let levelConditionBall: LevelConditionBall = ballObj.getComponent("LevelConditionBall");
                levelConditionBall.setBallMode(GameMain.instance.getBallSpriteFrame(levelCfg.conditions[i].cid), levelCfg.conditions[i].num, levelCfg.conditions[i].cid);
                this.conditionBalls.push(levelConditionBall);
            }
        }
        else if(levelCfg.levelType===1)
        {
            let ballsCnt:number=levelCfg.lineGameBalls.length;
            for (let i = 0; i < ballsCnt; i++)
            {
                let ballObj = instantiate(this.ballPrefab);
                this.ballAttach.addChild(ballObj);
                //ballObj.name ="";
                ballObj.setPosition((i - (ballsCnt-1)*0.5) * MainUI.conditionBallInterval[ballsCnt-1], 0, 0);

                let levelConditionBall: LevelConditionBall = ballObj.getComponent("LevelConditionBall");
                levelConditionBall.setLineGameMode(GameMain.instance.getBallSpriteFrame(levelCfg.lineGameBalls[i].val), levelCfg.lineGameBalls[i].val);
                this.conditionBalls.push(levelConditionBall);
            }
        }

        this.topBarBgSprite.spriteFrame=this.diffSpriteFrames[levelCfg.diff];
        if(levelCfg.diff>0)
        {
            this.topBarTitleSprite.node.active=false;
            this.topBarTitleSprite.spriteFrame=this.diffTitleSpriteFrames[levelCfg.diff - 1];
            if(levelCfg.diff===1)
                this.topBarTitleLabel.string="挑战关卡";
            else if(levelCfg.diff===2)
                this.topBarTitleLabel.string="困难关卡";
        }
        else
        {
            this.topBarTitleSprite.node.active=false;
        }
    }

    public revive()
    {
        this.remainSteps=3;
        this.stepNumLabel.string=""+this.remainSteps;
    }

    public notifyBallConnectedInLineGame(val:number , connected:boolean , changeBallState:boolean=true):boolean
    {
        if(changeBallState)
        {
            for (let i = 0; i < this.conditionBalls.length; i++)
            {
                if (this.conditionBalls[i].colorId === val && this.conditionBalls[i].connected === !connected)
                {
                    this.conditionBalls[i].lineConnected(connected);
                    break;
                }
            }
        }

        this.remainSteps -= 1;
        this.stepNumLabel.string = "" + this.remainSteps;
        tween(this.stepNumLabel.node).to(0.2, {scale:v3(1.3, 1.3, 1)}).to(0.5,{scale:Vec3.ONE}, {easing:"backOut"}).call(()=>{

        }).start();

        //check all balls
        let isAllClear:boolean=true;
        for(let i=0;i<this.conditionBalls.length;i++)
        {
            if(!this.conditionBalls[i].connected)
            {
                isAllClear = false;
                break;
            }
        }

        if(this.remainSteps<=0 && !isAllClear)
        {
            //关卡失败
            GameMain.instance.gameOverUI.show();
        }

        if(isAllClear && this.remainSteps>=0)
        {
            //关卡成功
            //剩余步数星星动画

            AudioManager.playClip(AudioClipID.LevelPass);

            if (!GameMain.instance.curLevelPassed)
            {
                GameMain.instance.curLevelPassed = true;
                GameMain.instance.nextLevel();
            }

            //star dst 的local pos
            let dstWorldPos:Vec3=this.starNode.getComponent(UITransform).convertToWorldSpaceAR(Vec3.ZERO);
            let dstLocalPos:Vec3=this.starAttachNode.getComponent(UITransform).convertToNodeSpaceAR(dstWorldPos);

            let delay:number=this.remainSteps * 0.1 + 1.3;

            if(this.remainSteps>0)
            {
                let remain:number=this.remainSteps;
                this.remainSteps=0;

                GameMain.instance.addStar(remain);

                for(let i=0;i<remain;i++)
                {
                    this.scheduleOnce(()=>{
                        let starObj=instantiate(this.starPrefab);
                        this.starAttachNode.addChild(starObj);
                        starObj.setPosition(0, -i * 12, 0);
                        starObj.setScale(0.3, 0.3, 1);
                        tween(starObj).to(0.2,{scale:Vec3.ONE}).start();

                        this.scheduleOnce(()=>{
                            tween(starObj).to(0.5 ,{position: dstLocalPos}, {easing: "backIn"}).call(() =>
                            {
                                this.trigStarNodeScale();
                                starObj.removeFromParent(true);
                                starObj.destroy();
                            }).start();
                        }, 0.45);
                    }, 0.1*i);
                }

                this.scheduleOnce(()=>{
                    //更新剩余步数显示
                    this.stepNumLabel.string=""+0;
                    this.updateStarLabel();
                    GameMain.instance.playLevelPassEffect();
                }, 1);
            }

            this.scheduleOnce(()=>{
                GameMain.instance.resultUI.show();
            }, delay);
        }

        return isAllClear;
    }

    public notifyBallConnected(ballVal:number, ballCount:number, reduceStep:boolean=true):boolean
    {
        for(let i=0;i<this.conditionBalls.length;i++)
        {
            if((this.conditionBalls[i].colorId===ballVal || this.conditionBalls[i].colorId===BallColorIdx.c) && this.conditionBalls[i].num>0)
            {
                this.conditionBalls[i].ballsCollected(ballCount);
            }
        }

        //check all balls
        let isAllClear:boolean=true;
        for(let i=0;i<this.conditionBalls.length;i++)
        {
            if(!this.conditionBalls[i].isClear())
            {
                isAllClear = false;
                break;
            }
        }

        if(reduceStep)
        {
            this.remainSteps -= 1;
            this.stepNumLabel.string = "" + this.remainSteps;
            tween(this.stepNumLabel.node).to(0.2, {scale:v3(1.3, 1.3, 1)}).to(0.5,{scale:Vec3.ONE}, {easing:"backOut"}).call(()=>{

            }).start();
        }

        if(this.remainSteps<=0 && !isAllClear)
        {
            //关卡失败
            GameMain.instance.gameOverUI.show();
        }

        if(isAllClear && this.remainSteps>=0)
        {
            //关卡成功
            //剩余步数星星动画

            AudioManager.playClip(AudioClipID.LevelPass);

            if(!GameMain.instance.curLevelPassed)
            {
                GameMain.instance.curLevelPassed=true;
                GameMain.instance.nextLevel();
            }

            //star dst 的local pos
            let dstWorldPos:Vec3=this.starNode.getComponent(UITransform).convertToWorldSpaceAR(Vec3.ZERO);
            let dstLocalPos:Vec3=this.starAttachNode.getComponent(UITransform).convertToNodeSpaceAR(dstWorldPos);

            let delay:number=this.remainSteps * 0.1 + 1.3;

            if(this.remainSteps>0)
            {
                let remain:number=this.remainSteps;
                this.remainSteps=0;
                console.log("** 关卡剩余步数="+remain);

                GameMain.instance.addStar(remain);

                console.log("** 创建 " + remain + "个 starobj");
                for(let i=0;i<remain;i++)
                {
                    this.scheduleOnce(()=>{
                        let starObj=instantiate(this.starPrefab);
                        this.starAttachNode.addChild(starObj);
                        starObj.setPosition(0, -i * 12, 0);
                        starObj.setScale(0.3, 0.3, 1);
                        tween(starObj).to(0.2,{scale:Vec3.ONE}).start();

                        this.scheduleOnce(()=>{
                            tween(starObj).to(0.5 ,{position: dstLocalPos}, {easing: "backIn"}).call(() =>
                            {
                                this.trigStarNodeScale();
                                starObj.removeFromParent(true);
                                starObj.destroy();
                            }).start();
                        }, 0.45);
                    }, 0.1*i);
                }

                this.scheduleOnce(()=>{
                    //更新剩余步数显示
                    this.stepNumLabel.string=""+0;
                    this.updateStarLabel();
                    GameMain.instance.playLevelPassEffect();
                }, 1);
            }

            this.scheduleOnce(()=>{
                if(Platform.currentPlatform===PlatformType.WECHAT && GameMain.instance.gameData.curLevelId===4)
                {
                    GameMain.instance.wxShareUI.show();
                }
                else
                {
                    GameMain.instance.resultUI.show();
                }
            }, delay);
        }
        return isAllClear;
    }

    public trigStarNodeScale()
    {
        /*
        if(Date.now() - this.dstLastScaleTime<110)
            return;
        this.dstLastScaleTime=Date.now();*/
        tween(this.starNode).to(0.05, {scale:v3(1.3, 1.3, 1.3)}).to(0.05,{scale:Vec3.ONE}).call(()=>{

        }).start();
    }

    public getConditionBallByColorId(colorId:number):LevelConditionBall
    {
        for(let i=0;i<this.conditionBalls.length;i++)
        {
            if(this.conditionBalls[i].colorId===colorId)
                return this.conditionBalls[i];
        }
        return null;
    }

    public getBallRemainNum(colorId:number):number
    {
        for(let i=0;i<this.conditionBalls.length;i++)
        {
            if(this.conditionBalls[i].colorId===colorId)
                return this.conditionBalls[i].num;
        }
        return 0;
    }

    public getColorBallRemainNum():number
    {
        for(let i=0;i<this.conditionBalls.length;i++)
        {
            if(this.conditionBalls[i].colorId===BallColorIdx.c)
            {
                return this.conditionBalls[i].num;
            }
        }
        return 0;
    }

    //更新strip显示
    public updateStrip()
    {
        let connectedLen:number=GameMain.instance.gameOper.connectedGrids.length;
        if(connectedLen>0)
        {
            if(!this.stripSprite.node.parent.active)
            {
                this.stripSpriteUITrans.width=0;
                this.stripLSpriteUITrans.width=0;
                this.stripRSpriteUITrans.width=0;
            }
            this.stripSprite.node.parent.active=true;

            //设置颜色
            let gridIdx:number=GameMain.instance.gameOper.connectedGrids[0];
            let stripColor:Color=GameMain.instance.grids[gridIdx].ball.getStripColor();
            this.stripSprite.color=stripColor;
            this.stripLSprite.color=stripColor;
            this.stripRSprite.color=stripColor;

            tween(this.stripSpriteUITrans).to(0.15, {width:260 * connectedLen }).call(()=>{
            }).start();

            tween(this.stripLSpriteUITrans).to(0.15, {width:260 * (connectedLen-3) }).call(()=>{
            }).start();
            tween(this.stripRSpriteUITrans).to(0.15, {width:260 * (connectedLen-3) }).call(()=>{
            }).start();

        }
        else
        {
            Tween.stopAllByTarget(this.stripSpriteUITrans);
            tween(this.stripSpriteUITrans).to(0.15, {width:0 }).call(()=>{
                this.stripSprite.node.parent.active=false;
            }).start();
        }
    }

    public onShareClicked()
    {
        //test code
        /*
        let startGameUI:StartGameUI=GameMain.instance.startGameUI;
        startGameUI.debugPring();*/

        //GameMain.instance.clearGameData();

        Platform.shareApp();
    }

    public onSettingClicked()
    {
        GameMain.instance.settingUI.show();
    }

    public getMoneyClicked()
    {
        GameMain.instance.getMoneyUI.show();
        //GameMain.instance.getMoneyUI.onGetClicked();
    }

    public onDailyAwardClicked()
    {
        GameMain.instance.dailyAwardUI.show();
    }

    public onRankClicked()
    {
        GameMain.instance.rankUI.show();
    }

    public onMoreGameClicked()
    {
        if(Platform.isAndroid())
        {
            GameMain.instance.sendNativeEvent(NativeEvt.MoreGame);
        }
    }

    public onAddShortClicked()
    {
        if(Platform.isOV())
        {
            Platform.addShortcut(() =>
            {
                Platform.showToast("桌面图标已创建");
            });
        }
        else if(Platform.currentPlatform===PlatformType.TT)
        {

        }
    }

    update(dt:number)
    {
    }

    public testClicked()
    {
        GameMain.instance.clearGameData();
    }
}











